package UDP2;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.util.Scanner;

public class Receive {
    public static void main(String[] args) throws IOException {
        System.out.println("服务器启动");
        DatagramSocket ds=new DatagramSocket(8080);
        DatagramPacket dp=new DatagramPacket(new byte[1024],1024);
        Scanner sc=new Scanner(System.in);
//        System.out.println("请输入发送消息的格式：");
//        System.out.println("1:对方说:"+"\n"+"2:对方说："+"\n");
//        System.out.println("2：");
//        int n=sc.nextInt();
        while (true) {
            ds.receive(dp);
            String data=new String(dp.getData(),0,dp.getLength());
            System.out.println("对方说："+data);
            String ip=dp.getAddress().getHostAddress();
            int port=dp.getPort();
            System.out.println("对方ip： "+ip+" "+"对方端口："+port);
            System.out.println();
        }
    }
}
